/*
 *  $Id: CardCategory.cs 1055 2010-05-19 12:02:44Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima {
    /// <summary>
    /// Категория карт, определяющая условия для включения карты в колоду и для целостности колоды.
    /// </summary>
    public class CardCategory {
        public static readonly CardCategory None = new CardCategory();
        public static readonly CardCategory Ragima = new SingleCardCategory();
        public static readonly CardCategory Ward = new SingleCardCategory();

        public virtual bool CanAddToDeck(Card card, CardDeck deck) {
            return true;
        }
        public virtual bool CheckDeck(Card card, CardDeck deck) {
            return true;
        }
    }

    /// <summary>
    /// Категория карт, из которой в колоде может быть омшь одна карта.
    /// </summary>
    public class SingleCardCategory : CardCategory {
        public override bool CanAddToDeck(Card card, CardDeck deck) {
            foreach (DeckItem item in deck)
                if (item.Card.Category == this && item.Card != card)
                    return false;
            return true;
        }
        public override bool CheckDeck(Card card, CardDeck deck) {
            int count = 0;
            foreach (DeckItem item in deck)
                if (item.Card.Category == this)
                    count++;
            return count <= 1;
        }
    }
}
